import React from 'react';
import {connect} from "dva";
import {Table, Row, Col, Form, Input, Icon, InputNumber, Select, Button, message} from 'antd';
import SingleDragger from "../commons/SingleDragger";
import Constants from "../../utils/Constants";

const R = require('ramda');
const {TextArea} = Input;
const FormItem = Form.Item;


export default Form.create({wrappedComponentRef: true})(class AccountInfos extends React.Component {
        constructor(props) {
            super(props);
            this.state = {
                url: ""
            }
        }

        handleResetFields = () => {
            this.props.form.resetFields();
        }

        handleConfirm = () => {
            let flag = false;

            this.props.form.validateFields((errors, values) => {
                if (errors) return;
                flag = true;

                let url = this.refs.url.getUrl();
                if (!R.isNil(url) && !R.isEmpty(url)) {
                    values.filename = url.substring(url.lastIndexOf('/') + 1, url.length);
                }
                values.url = url;

                this.props.dispatch({
                    type: "settlement/createStatement",
                    payload: {
                        ...values,
                        cstId: this.props.cstId,
                        stObj: "4",
                        stObjId: 999999999,
                        accname: "1",
                        accno: this.props.accno,
                        accopenbank: this.props.accopenbank,
                        statementDetailForm: this.props.statementFee,
                        onSuccess: ()=>{
                            if(this.props.handleSearch) this.props.handleSearch()
                        }
                    }
                })
            });

            return flag;
        }



        render() {
            const {getFieldDecorator} = this.props.form;
            const formItemLayout = {labelCol: {xs: {span: 8}, sm: {span: 5}}, wrapperCol: {xs: {span: 15}, sm: {span: 14}}};
            let dataSource = R.isNil(this.props.dataSource) ? {} : this.props.dataSource;

            return (

                <Form>
                    <FormItem {...formItemLayout} label="本次结算金额" hasFeedback>
                        {getFieldDecorator('transferamount', {
                            initialValue: this.props.transferamount
                        })(
                            <InputNumber style={{width: '100%'}} maxLength="20" disabled={true}/>
                        )}
                    </FormItem>

                    <FormItem {...formItemLayout} label="出货备注" hasFeedback>
                        {getFieldDecorator('memo', {
                            rules: [{
                                required: true, message: '请输入本单出货备注'
                            }],
                            initialValue: ""
                        })(
                            <TextArea autosize={{minRows: 2, maxRows: 10}} maxLength="500"/>
                        )}
                    </FormItem>

                    <FormItem {...formItemLayout} label="转账确认函" hasFeedback>
                        <SingleDragger url={dataSource.url} ref="url" dataSource={dataSource}
                                       module={this.state.module}/>
                    </FormItem>
                </Form>
            );
        }
})




// WEBPACK FOOTER //
// ./public/src/components/order/components/AccountInfos.js